#include <stdio.h>
#include <string>
#include <uriparser/Uri.h>

#pragma comment(lib, "D:/Downloads/uriparser-0.7.5/uriparser-0.7.5/win32/uriparser.lib")

using std::string;

int main (int argc, char *argv[])
{
	UriParserStateA state;
	UriUriA uri;

	state.uri = &uri;

	if (uriParseUriA(&state, "http://uriparser.sourceforge.net:2121/doc/html/globals_func.html") != URI_SUCCESS) {
		uriFreeUriMembersA(&uri);
		printf("Parse uri failed\n");
		return -1;
	}

	printf("URI components: \n");
	string scheme(uri.scheme.first, uri.scheme.afterLast);
	printf("Scheme: %s\n", scheme.c_str());

	scheme.assign(uri.hostText.first, uri.hostText.afterLast);
	printf("Host: %s\n", scheme.c_str());

	scheme.assign(uri.portText.first, uri.portText.afterLast);
	if (scheme.empty()) {
		printf("Port: %d\n", 80);
	} else {
		printf("Port: %d\n", atoi(scheme.c_str()));
	}

	uriFreeUriMembersA(&uri);
	return 0;
}